package com.lbs.jiepiaisi.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.amap.api.navi.enums.PathPlanningStrategy;
import com.lbs.jiepiaisi.R;

/**
 *
 * 时间：2017/7/28 10:32
 * 作用：导航偏好设置
 */

public class AccountChaseCarPreferenceActivity extends Activity {

    private LinearLayout liner_close;
    private ImageView image_avoid_wall;//避免拥堵
    private ImageView image_avoid_charge;//避免收费
    private ImageView image_avoid_highway;//不走高速
    private ImageView image_highway_priority;//高速优先
    private static int avoid_wall=0;//避免拥堵点击标识
    private static int avoid_highway=0;//避免收费点击标识
    private static int avoid_charge=0;//不走高速点击标识
    private static int highway_priority=0;//高速优先点击标识
    private Button btn_ok; //完成
    private int drivingMode;//驾车模式
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_preference);
        getExras();
        findView();
        setListener();
    }

    private void getExras() {

    }
    private void findView() {
        liner_close= (LinearLayout) findViewById(R.id.liner_close);
        image_avoid_wall= (ImageView) findViewById(R.id.image_avoid_wall);//避免拥堵
        image_avoid_charge= (ImageView) findViewById(R.id.image_avoid_charge);//避免收费
        image_avoid_highway= (ImageView) findViewById(R.id.image_avoid_highway);//不走高速
        image_highway_priority= (ImageView) findViewById(R.id.image_highway_priority);//高速优先
        btn_ok= (Button) findViewById(R.id.btn_ok);
    }
    private void setListener() {
        liner_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                image_avoid_wall//避免拥堵
//                image_avoid_charge//避免收费
//                image_avoid_highway//不走高速
//                image_highway_priority;//高速优先
                //只选了避免拥堵
                if(image_avoid_wall.isSelected()==true
                        &&image_avoid_charge.isSelected()==false
                        &&image_avoid_highway.isSelected()==false
                        &&image_highway_priority.isSelected()==false){
                    drivingMode= PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_AVOID_CONGESTION;
                }
                //只选了避免收费
                else if(image_avoid_wall.isSelected()==false
                        &&image_avoid_charge.isSelected()==true
                        &&image_avoid_highway.isSelected()==false
                        &&image_highway_priority.isSelected()==false){
                    drivingMode= PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_AVOID_COST;
                }
                //只选了不走高速
                else if(image_avoid_wall.isSelected()==false
                        &&image_avoid_charge.isSelected()==false
                        &&image_avoid_highway.isSelected()==true
                        &&image_highway_priority.isSelected()==false){
                    drivingMode= PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_AVOID_HIGHSPEED;
                }
                //只选了高速优先
                else if(image_avoid_wall.isSelected()==false
                        &&image_avoid_charge.isSelected()==false
                        &&image_avoid_highway.isSelected()==false
                        &&image_highway_priority.isSelected()==true){
                    drivingMode= PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_PRIORITY_HIGHSPEED;
                }
                //不走高速&躲避拥堵
                else if(image_avoid_wall.isSelected()==true
                        &&image_avoid_charge.isSelected()==false
                        &&image_avoid_highway.isSelected()==true
                        &&image_highway_priority.isSelected()==false){
                    drivingMode= PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_AVOID_HIGHSPEED_CONGESTION;
                }
               //不走高速&避免收费
                else if(image_avoid_wall.isSelected()==false
                        &&image_avoid_charge.isSelected()==true
                        &&image_avoid_highway.isSelected()==true
                        &&image_highway_priority.isSelected()==false){
                    drivingMode= PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_AVOID_HIGHTSPEED_COST;
                }
                //避免收费&躲避拥堵
                else if(image_avoid_wall.isSelected()==true
                        &&image_avoid_charge.isSelected()==true
                        &&image_avoid_highway.isSelected()==false
                        &&image_highway_priority.isSelected()==false){
                    drivingMode= PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_AVOID_COST_CONGESTION;
                }
                //不走高速&避免收费&躲避拥堵
                else if(image_avoid_wall.isSelected()==true
                        &&image_avoid_charge.isSelected()==true
                        &&image_avoid_highway.isSelected()==true
                        &&image_highway_priority.isSelected()==false){
                    drivingMode= PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_AVOID_HIGHSPEED_COST_CONGESTION;
                }
                //高速优先
                else if(image_avoid_wall.isSelected()==false
                        &&image_avoid_charge.isSelected()==false
                        &&image_avoid_highway.isSelected()==false
                        &&image_highway_priority.isSelected()==true){
                    drivingMode= PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_PRIORITY_HIGHSPEED;
                }
                //高速优先&躲避拥堵
                else if(image_avoid_wall.isSelected()==true
                        &&image_avoid_charge.isSelected()==false
                        &&image_avoid_highway.isSelected()==false
                        &&image_highway_priority.isSelected()==true){
                    drivingMode= PathPlanningStrategy.DRIVING_MULTIPLE_ROUTES_PRIORITY_HIGHSPEED_AVOID_CONGESTION;
                }

                //数据是使用Intent返回
                Intent intent = new Intent();
                //把返回数据存入Intent
                intent.putExtra("resultView",drivingMode);
                AccountChaseCarPreferenceActivity.this.setResult(0,intent);

                finish();
            }
        });
        btn_ok.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        //避免拥堵
        image_avoid_wall.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(avoid_wall==0){//确定
                            avoid_wall=1;
                            image_avoid_wall.setSelected(true);
                        }else{//取消
                            avoid_wall=0;
                            image_avoid_wall.setSelected(false);
                        }
            }
        });
        //避免收费
        image_avoid_charge.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                        if(avoid_charge==0){//确定
                            avoid_charge=1;
                            image_avoid_charge.setSelected(true);
                            //选择避免收费后，高速优先将被取消
                            highway_priority=0;
                            image_highway_priority.setSelected(false);
                        }else{//取消
                            avoid_charge=0;
                            image_avoid_charge.setSelected(false);
                        }
            }
        });
        //不走高速
        image_avoid_highway.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(avoid_highway==0){//确定
                            avoid_highway=1;
                            image_avoid_highway.setSelected(true);
                            //如果选择不走高速，高速优先将被取消
                            highway_priority=0;
                            image_highway_priority.setSelected(false);
//                            //驾车路径规划
//                            drivingMode = PathPlanningStrategy .DRIVING_MULTIPLE_ROUTES_AVOID_HIGHSPEED_COST_CONGESTION;
//                            //驾车路径规划
//                            drivingRoute();
                        }else{//取消
                            avoid_highway=0;
                            image_avoid_highway.setSelected(false);
                        }
            }
        });
        //高速优先
        image_highway_priority.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(highway_priority==0){//确定
                            highway_priority=1;
                            image_highway_priority.setSelected(true);
                            //选择高速优先，不走高速将被取消
                            avoid_highway=0;
                            image_avoid_highway.setSelected(false);
                            //选择高速优先，避免收费将被取消
                            avoid_charge=0;
                            image_avoid_charge.setSelected(false);
//                            //驾车路径规划
//                            drivingMode = PathPlanningStrategy .DRIVING_MULTIPLE_ROUTES_PRIORITY_HIGHSPEED;
//                            drivingRoute();
                        }else{//取消
                            highway_priority=0;
                            image_highway_priority.setSelected(false);
                        }

            }
        });

    }
}
